package com.droid.lib.controls.demo.view;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.droid.lib.controls.demo.R;
import com.droid.lib.controls.demo.activity.MainActivity;
import com.droid.lib.controls.demo.adapter.MenuAdapter;
import com.droid.lib.controls.demo.adapter.MenuAdapter.OnClicker;

import java.util.ArrayList;

/**
 * 底部动作框
 *
 * @author Administrator
 */
public class BottomSheetFragmentDemo extends Fragment {
    private Context mContext;
    private ListView mListview;
    private MenuAdapter mAdapter;
    private ArrayList<String> arrStrs;
    String[] items = new String[]{"From Xml", "Without Icon", "Dark Theme", "Grid", "Style", "Style from Theme", "ShareAction", "FullScreen", "Menu Manipulate", "HeaderLayout","From Fragment"};

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mContext = getActivity();
        View view = inflater.inflate(R.layout.fragment_bottom_sheet, null);
        mListview = (ListView) view.findViewById(R.id.listview);
        mAdapter = new MenuAdapter(getActivity());
        mListview.setAdapter(mAdapter);
        arrStrs = new ArrayList<String>();
        for (int a = 0; a < items.length; a++) {
            arrStrs.add(items[a]);
        }
        mAdapter.setList(arrStrs);
        mAdapter.setOnClicker(new OnClicker() {

            @Override
            public void onclick(final int position) {
                if(position != items.length - 1){
                    ((MainActivity) mContext).showDialog(position);
                }
                else{
                    new BottomSheetDetailFragment().show(getChildFragmentManager(), R.id.rl_in_parent);
                }
            }
        });
        return view;
    }

}
